package com.example.rabbitmq_study.HelloWorld;

import com.example.rabbitmq_study.util.RabbitmqUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author Huangyt
 * @version 1.0
 * @date 2020/7/28 11:34
 */
public class Provider {
    /*
        生产消息
     */
    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接对象
        Connection connection = RabbitmqUtil.getConnection();

        //获取连接中的通道
        Channel channel = connection.createChannel();

        //声明队列
        channel.queueDeclare("hello"/*队列名*/, true/*持久化*/, false/*独占*/, false/*自动删除*/, null/*map额外参数*/);

        //发布消息
        channel.basicPublish("", "hello", MessageProperties.PERSISTENT_BASIC, "Hello rabbitmq".getBytes());

        //通道，连接关闭
        RabbitmqUtil.close(channel, connection);
    }

}
